package com.yylending.las.lending.video;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * Created by HenryZhang on 2017/7/12.<br>
 * Copyright © 2017 www.yylending.com. All Rights Reserved.<br><br>
 */
public class SignPresenter extends Presenter<SignModel, SignPresenter.View> {
	private static final String TAG = "SignPresenter";

	public static class Generator implements PresenterFactory<SignPresenter> {
		@Override
		public SignPresenter create() {
			return new SignPresenter();
		}
	}

	public interface View extends IView {
		void onSignResult(SignModel.Sign sign);
		void onSignFailed(String msg);
	}

	private View mView;

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new SignModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public void getSign() {
		execute();
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void onSignResult(SignModel.AnyChatSign result) {
		CLog.i(TAG, "result = " + result);
		if (BaseResultEntity.isResponseSuccess(result)) {
			mView.onSignResult(result.getData());
		} else {
			mView.onSignFailed(result.getRetMsg());
		}
	}
}
